<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/10 0010
 * Time: 15:20
 */

namespace app\admin\controller;
use app\common\model\WxConfig as WxConfigModel;
use app\common\validate\WxConfigValidate;


class WxConfig extends Common
{

    /**
     * 微信配置项
     * @return \think\response\Json|\think\response\View
     * @throws \think\Exception
     * @throws \think\Exception\DbException
     */
    public function index() {

        if ($this->request->isAjax()) {

            $wx_config_validate = (new WxConfigValidate());
            $wx_config_validate->goCheck();
            $param = $wx_config_validate->getDataByRule();

            $data = WxConfigModel::saveInfo($param);

            return $data;
        }

        $data = WxConfigModel::all();
        $wx_config = [];
        foreach ($data as $v) {
            $wx_config[$v->key] = $v->value;
        }
        $this->assign('wx_config', $wx_config);
        return view();
    }

}